package name.huzhenbo.java.patterns.iterator;

public class MyStringList {
    private String[] array;

    public MyStringList(String[] array) {
        this.array = array;
    }

    public Iterator createIterator() {
        return new MyStringListIterator(this);
    }

    public int size() {
        return array.length;
    }

    public String get(int index) {
        return array[index];
    }

    private class MyStringListIterator implements Iterator {
        private MyStringList list;
        private int current = 0;

        public MyStringListIterator(MyStringList list) {
            this.list = list;
        }

        public boolean hasNext() {
            return current < list.size() - 1;
        }

        public String next() {
            return list.get(current++);
        }
    }

}
